package cn.net.yugu.doraemon.datahub.factory;

import cn.net.yugu.doraemon.datahub.config.DataHubProperties;
import com.aliyun.datahub.client.DatahubClient;
import com.aliyun.datahub.client.DatahubClientBuilder;
import com.aliyun.datahub.client.auth.AliyunAccount;
import com.aliyun.datahub.client.common.DatahubConfig;
import com.aliyun.datahub.client.http.HttpConfig;

/**
 * @description: DataHubClientFactory
 * @author: wanghongli
 * @create: 2022-07-17 11:01:34
 */
public final class DataHubClientFactory {
    public static DatahubClient create(DataHubProperties properties) {
        return DatahubClientBuilder.newBuilder()
                .setDatahubConfig(
                        new DatahubConfig(properties.getEndpoint(),
                                new AliyunAccount(properties.getAccessId(), properties.getAccessKey()), true))
                .setHttpConfig(new HttpConfig()
                        .setCompressType(HttpConfig.CompressType.LZ4)
                        .setConnTimeout(properties.getConnTimeout()))
                .build();
    }
}
